package com.panda.controller;

import com.panda.model.ProductInfo;
import com.panda.param.ProductInfoQueryParam;
import com.panda.service.ProductInfoService;
import com.panda.vo.ProductInfoOutVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/product")
@ResponseBody
public class ProductInfoController {

    @Autowired
    private ProductInfoService productInfoService;

    @PostMapping("/list")
    public List<ProductInfoOutVO> productInfoList(@RequestBody ProductInfoQueryParam queryParam) {
        List<ProductInfo> list = productInfoService.list(queryParam);
        ArrayList<ProductInfoOutVO> productInfoOutVOS = new ArrayList<>();
        for (ProductInfo productInfo : list) {
            ProductInfoOutVO productInfoOutVO = new ProductInfoOutVO();
            BeanUtils.copyProperties(productInfo, productInfoOutVO);
            productInfoOutVOS.add(productInfoOutVO);
        }
        return productInfoOutVOS;
    }
}
